package com.cqw.commontest;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;

import javax.xml.datatype.DatatypeFactory;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @author cqw
 * @date 2022/7/21
 */
public class Test1111 {

    public static void main(String[] args) {

//
//        Date date = stringToDate("2022-08-01 13:00", "yyyy-MM-dd HH:mm");
//        System.out.println(date);
//
//        System.out.println(dateToString(date,"yyyy-MM-dd HH:mm:ss"));

        Date truncate = DateUtils.truncate(new Date(), Calendar.MONTH);


        String day = "8";
        int interval = Integer.parseInt(day) / 5;  //1
        System.out.println(interval);
        int start = interval * 5 + 1;
        System.out.println(start);   //6
        Date startDate = DateUtils.addDays(DateUtils.truncate(new Date(), Calendar.MONTH), start - 1);
        System.out.println(dateToString(startDate,"yyyy-MM-dd HH:mm:ss"));
        int end = (interval + 1) * 5;    //10
        System.out.println(end);



    }

    public static Date stringToDate(String str, String pattern) {
        if (StringUtils.isBlank(str)) {
            return null;
        }
        SimpleDateFormat formatter = new SimpleDateFormat(pattern);
        Date strtodate = null;
        try {
            strtodate = formatter.parse(str);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return strtodate;
    }

    public static String dateToString(Date dateDate, String pattern) {
        if (dateDate == null) {
            return null;
        }
        SimpleDateFormat formatter = new SimpleDateFormat(pattern);
        String dateString = formatter.format(dateDate);
        return dateString;
    }

}
